﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using Company.Database.Sqlite;
using Company.Shell.Models;
using Company.Shell.Views;
using Microsoft.Extensions.DependencyInjection;
using System.Windows;

namespace Company.Shell.ViewModels
{
    internal class ShellViewModel : ObservableObject
    {
        private Visibility show = Visibility.Collapsed;
        /// <summary>
        /// 是否显示页面的遮罩层
        /// </summary>
        public Visibility Show
        {
            get { return show; }
            set { SetProperty(ref show, value); }
        }
        private object? content;
        /// <summary>
        /// 页面
        /// </summary>
        public object? Content
        {
            get { return content; }
            set { SetProperty(ref content, value); }
        }

        public ShellViewModel()
        {
            Content = App.Current.Services.GetService<InitializeView>();//启动时默认显示页面

            //当硬件加载成功后，跳转到主页
            WeakReferenceMessenger.Default.Register<InitializeSuccessMessage>(this, (sender, arg) =>
            {
                Content = App.Current.Services.GetService<MainView>();
                var window = App.Current.MainWindow;
                window.WindowState = System.Windows.WindowState.Normal;
                window.Width = 1800;
                window.Height = 1000;
                SetWindow(window);
            });
        }

        private void SetWindow(Window window)
        {
            window.Left = (SystemParameters.WorkArea.Width - window.Width) / 2;
            window.Top = (SystemParameters.WorkArea.Height - window.Height) / 2;
        }
    }
}
